package com.example.myspringframework.beans.factory.support;

import com.example.myspringframework.beans.BeansException;
import com.example.myspringframework.beans.factory.config.BeanDefinition;

/**
 * 通过无参构造函数实例化策略
 */
public class SimpleInstantiationStrategy implements InstantiationStrategy {

    @Override
    public Object instantiate(BeanDefinition beanDefinition) throws BeansException {
        Class<?> beanClass = beanDefinition.getBeanClass();
        try {
            return beanClass.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            throw new BeansException("Failed to instantiate [" + beanClass.getName() + "]", e);
        }
    }

}
